package com.club.subject.domain.handler.subject;

import com.club.subject.common.enums.IsDeletedFlagEnum;
import com.club.subject.common.enums.SubjectInfoTypeEnum;
import com.club.subject.domain.convert.SubjectMultipleInfoConverter;
import com.club.subject.domain.convert.SubjectRadioInfoConverter;
import com.club.subject.domain.entity.SubjectInfoBO;
import com.club.subject.domain.entity.SubjectOptionBO;
import com.club.subject.infra.baisc.entity.SubjectMultiple;
import com.club.subject.infra.baisc.entity.SubjectRadio;
import com.club.subject.infra.baisc.service.SubjectMultipleService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: sfy
 * @Date: 2024/4/13 12:38
 * @Description: 多选
 */
@Component
public class MultipleTypeHandler implements SubjectTypeHandler {

    @Resource
    private SubjectMultipleService subjectMultipleService;

    /**
     * 枚举身份的识别
     *
     * @return
     */
    @Override
    public SubjectInfoTypeEnum getHandlerType() {
        return SubjectInfoTypeEnum.MULTIPLE;
    }

    /**
     * 实际题目的插入
     *
     * @param subjectInfoBO
     */
    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        List<SubjectMultiple> list = new ArrayList<>();
        subjectInfoBO.getOptionList().forEach(option -> {
            SubjectMultiple subjectMultiple = SubjectMultipleInfoConverter.INSTANCE.convertBoToMultiple(option);
            subjectMultiple.setSubjectId(subjectInfoBO.getId());
            subjectMultiple.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode());
            list.add(subjectMultiple);
        });
        subjectMultipleService.batchInsert(list);
    }

    /**
     * @param subjectId
     */
    @Override
    public SubjectOptionBO query(int subjectId) {
        return null;
    }
}
